/*	Copyright 2007 - Xavier Baro (xbaro@cvc.uab.cat)

	This file is part of eapmlib.

    Eapmlib is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or any 
	later version.

    Eapmlib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __PROBMODEL_H__
#define __PROBMODEL_H__

#include "EvolutiveLib.h"
#include "Population.h"
#include "Evaluator.h"

namespace Evolutive {

	class EVOLUTIVELIB_API CProbModel
	{
		//! Methods
	public:
		//! Default constructor		
		CProbModel(void);
		
		//! Default destructor
		virtual ~CProbModel(void);

		//! Indicates when the model is at a standstill
		virtual bool IsStatic(double Tolerance) = 0;

		//! Generates a new population using the probability distribution
		void NewPopulation(CPopulation &Population,CODING_METHOD ModelCode);

		//! Generates a new population using the probability distribution using an evaluator to check the new individuals
		virtual void NewPopulation(CPopulation &Population,CODING_METHOD ModelCode,CEvaluator *Evaluator) = 0;

		//! Updates the model using an individual
		virtual void Update(CChromosome &C) = 0;

		//! Estimate a model from the data		
		virtual void Estimate(int NumIndividuals,CPopulation &Population) = 0;	

		//! Initialize the probability model
		virtual void InitializeModel(int NumVars,CPopulation &Population);

		//! Set the variable range
		void SetRange(int VarIdx,int MinVal,int MaxVal);

		//! Set the same range to all the variables
		void SetEqualRanges(int MinVal,int MaxVal);

		//! Set the percentage of worse elements to use when estimate the model
		void SetEstimationWorseElements(double Percentage);
		
	protected:
					
		//! Attributes
	protected:
		//! Number of random variables of the problem
		int m_NumVars;		

		//! Defines the minimum value for each variable
		int *m_VarRangeMin;

		//! Defines the maximum value for each variable
		int *m_VarRangeMax;			

		//! Defines the percentage of worse individuals used to estimate the model
		double m_EstimationWorsePer;
	};	
}
	EVOLUTIVELIB_API Evolutive::CProbModel& operator<<(Evolutive::CProbModel &ProbModel, Evolutive::CChromosome C);

#endif // __PROBMODEL_H__
